home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Frameworks / TransSkel 3.18 / Demos / C Demos / Skel / Skel.c next >
Encoding:
C/C++ Source or Header  |  1994-05-15  |  5.9 KB  |  257 lines  |  [TEXT/KAHL]

  1. /*
  2.  * TransSkel demonstration:  Traditional Skel
  3.  *
  4.  * This program mimics the original Skel application:  one sizable,
  5.  * dragable, non-closable dark gray window, an "About" alert and two
  6.  * dialogs.  Desk accessories supported.
  7.  *
  8.  * 21 Apr 88 Paul DuBois
  9.  * 29 Jan 89 Version 1.01
  10.  * - Conversion for TransSkel 2.0.
  11.  * 12 Jan 91 Version 1.02
  12.  * - Conversion for TransSkel 3.00.
  13.  * 05 Jun 93 Version 1.03
  14.  * - Conversion for THINK C 6.0.
  15.  * 18 Jan 94 Version 1.04
  16.  * - Used TransSkel positioning routines to position About alert and the
  17.  * dialog box on the screen.  The dialog resource also was made initially
  18.  * invisible, since otherwise it appears and then moves.  Also added
  19.  * a user item for outlining the default button.
  20.  * 21 Feb 94
  21.  * - Updated for TransSkel 3.11.
  22.  */
  23.  
  24. # include    "TransSkel.h"
  25.  
  26.  
  27. /*
  28.  * Resource numbers
  29.  */
  30.  
  31. # define    fileMenuRes        129        /* File menu */
  32. # define    aboutAlrtRes    1000    /* About box */
  33. # define    theWindRes        260        /* window */
  34. # define    reportDlog        257        /* message dialog box */
  35. # define    aboutStr        128        /* message strings */
  36. # define    rattleStr        129
  37. # define    frightStr        130
  38.  
  39.  
  40. /* dialog item numbers */
  41.  
  42. typedef enum
  43. {
  44.     okayItem = 1,
  45.     messageItem,
  46.     titleItem,
  47.     outlineItem
  48. };
  49.  
  50.  
  51. /* file menu item numbers */
  52.  
  53. typedef enum
  54. {
  55.     rattle = 1,
  56.     frighten,
  57.     /* --- */
  58.     quit = 4
  59. } fileItems;
  60.  
  61.  
  62. static WindowPtr    theWind;
  63.  
  64. /*
  65.  * Menu handles.  There isn't any apple menu here, since TransSkel will
  66.  * be told to handle it itself.
  67.  */
  68.  
  69. static MenuHandle    fileMenu;
  70.  
  71.  
  72. /* -------------------------------------------------------------------- */
  73. /*                        Menu handling procedures                        */
  74. /* -------------------------------------------------------------------- */
  75.  
  76.  
  77. /*
  78.  * Read a string resource and put into the Alert/Dialog paramtext
  79.  * values
  80.  */
  81.  
  82. static void
  83. SetParamText (short strNum)
  84. {
  85. StringHandle    h;
  86. SignedByte        flags;
  87.  
  88.     h = GetString (strNum);
  89.     flags = HGetState ((Handle) h);
  90.     HLock ((Handle) h);
  91.     ParamText (*h, "\p", "\p", "\p");
  92.     HSetState ((Handle) h, flags);
  93. }
  94.  
  95.  
  96. /*
  97.  * Put up a dialog box with a message and an OK button.  The message
  98.  * is stored in the 'STR ' resource whose number is passed as strNum.
  99.  */
  100.  
  101. static void
  102. Report (short strNum)
  103. {
  104. DialogPtr    theDialog;
  105. GrafPtr        savePort;
  106. short        itemHit;
  107.  
  108.     SetParamText (strNum);
  109.     theDialog = GetNewDialog (reportDlog, nil, (WindowPtr) -1L);
  110.     SkelPositionWindow (theDialog, skelPositionOnParentDevice,
  111.                                 FixRatio (1, 2), FixRatio (1, 5));
  112.     GetPort (&savePort);
  113.     SetPort (theDialog);
  114.     SkelSetDlogButtonOutliner (theDialog, outlineItem);
  115.     ShowWindow (theDialog);
  116.     ModalDialog (SkelDlogFilter (nil, true), &itemHit);
  117.     SkelRmveDlogFilter ();
  118.     DisposeDialog (theDialog);
  119.     SetPort (savePort);
  120. }
  121.  
  122.  
  123. /*
  124.  * Handle selection of "About Skel..." item from Apple menu
  125.  */
  126.  
  127. static pascal void
  128. DoAppleMenu (short item)
  129. {
  130.     SetParamText (aboutStr);
  131.     (void) SkelAlert (aboutAlrtRes, SkelDlogFilter (nil, true),
  132.                                             skelPositionOnParentDevice);
  133.     SkelRmveDlogFilter ();
  134. }
  135.  
  136.  
  137. /*
  138.  * Process selection from File menu.
  139.  *
  140.  * Rattle, Frighten    A dialog box with message
  141.  * Quit    Request a halt by calling SkelStopEventLoop().  This
  142.  *        makes SkelMain return.
  143.  */
  144.  
  145. static pascal void
  146. DoFileMenu (short item)
  147. {
  148.     switch (item)
  149.     {
  150.         case rattle:    Report (rattleStr); break;
  151.         case frighten:    Report (frightStr); break;
  152.         case quit:        SkelStopEventLoop (); break;    /* request halt */
  153.     }
  154. }
  155.  
  156.  
  157. /*
  158.  * Initialize menus.  Tell TransSkel to process the Apple menu
  159.  * automatically, and associate the proper procedures with the
  160.  * File and Edit menus.
  161.  *
  162.  * \311 is the ellipsis character.
  163.  */
  164.  
  165. static void
  166. SetUpMenus (void)
  167. {
  168.     SkelApple ("\pAbout Skel\311", DoAppleMenu);
  169.     fileMenu = GetMenu (fileMenuRes);
  170.     (void) SkelMenu (fileMenu, DoFileMenu, nil, false, true);
  171. }
  172.  
  173.  
  174. /* -------------------------------------------------------------------- */
  175. /*                    Window handling procedures                            */
  176. /* -------------------------------------------------------------------- */
  177.  
  178.  
  179. /*
  180.  * On update event, can ignore the resizing information, since the whole
  181.  * window is always redrawn in terms of the current size, anyway.
  182.  * Content area is dark gray except scroll bar areas, which are white.
  183.  * Draw grow box as well.
  184.  *
  185.  * Note that we can assume the current port is set to theWind.
  186.  */
  187.  
  188. static pascal void
  189. Update (Boolean resized)
  190. {
  191. Rect    r;
  192.  
  193.     r = theWind->portRect;        /* paint window dark gray */
  194.     r.bottom -= 15;                /* don't bother painting the */
  195.     r.right -= 15;                /* scroll bar areas */
  196.     FillRect (&r, (ConstPatternParam) &qd.dkGray);
  197.     r = theWind->portRect;        /* paint scroll bar areas white */
  198.     r.left = r.right - 15;
  199.     FillRect (&r, (ConstPatternParam) &qd.white);
  200.     r = theWind->portRect;
  201.     r.top = r.bottom - 15;
  202.     FillRect (&r, (ConstPatternParam) &qd.white);
  203.     DrawGrowIcon (theWind);
  204. }
  205.  
  206.  
  207. static pascal void
  208. Activate (Boolean active)
  209. {
  210.     DrawGrowIcon (theWind);    /* make grow box reflect new window state */
  211. }
  212.  
  213.  
  214. static pascal void
  215. Clobber (void)
  216. {
  217.     DisposeWindow (theWind);
  218. }
  219.  
  220.  
  221. /*
  222.  * Read window from resource file and install handler for it.  Mouse
  223.  * and key clicks are ignored.  There is no close proc since the window
  224.  * doesn't have a close box.  There is no idle proc since nothing is
  225.  * done while the window is in front (all the things that are done are
  226.  * handled by TransSkel).
  227.  */
  228.  
  229. static void
  230. WindInit (void)
  231. {
  232.     if (SkelQuery (skelQHasColorQD))
  233.         theWind = GetNewCWindow (theWindRes, nil, (WindowPtr) -1L);
  234.     else
  235.         theWind = GetNewWindow (theWindRes, nil, (WindowPtr) -1L);
  236.     if (theWind == (WindowPtr) nil)
  237.         return;
  238.     (void) SkelWindow (theWind, nil, nil, Update, Activate, nil,
  239.                     Clobber, nil, false);
  240. }
  241.  
  242.  
  243. /* -------------------------------------------------------------------- */
  244. /*                                    Main                                */
  245. /* -------------------------------------------------------------------- */
  246.  
  247.  
  248. int
  249. main (void)
  250. {
  251.     SkelInit ((SkelInitParamsPtr) nil);    /* initialize */
  252.     SetUpMenus ();                        /* install menu handlers */
  253.     WindInit();                            /* install window handler */
  254.     SkelEventLoop ();                    /* loop 'til Quit selected */
  255.     SkelCleanup ();                        /* clean up */
  256. }
  257.